import { deleteByPrimaryKeyForProDictionarys, selectByPrimaryKeyForProDictionarys, insertForProDictionarys, updateForProDictionarys, deleteByMapForProDictionarys,updateByMapForProDictionarys, getOneForProDictionarys,queryPageForProDictionarys, countForProDictionarys, insertBatchForProDictionarys, deleteBatchForProDictionarys,updateBatchForProDictionarys,getAllForProDictionarysType,insertForProDictionarysType,updateForProDictionarysType,deleteByPrimaryKeyForProDictionarysType,getAllChildren } from '@/services/system/api_prodictionarys';


export default {
    namespace: 'prodictionarys',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        dictionarysTree: {
        	list: [],
        },
        cascaderList: {
        	list: [],
        },
        dictionarysTypeBySelect: {
        	list: [],
        },
    },

    effects: {
            *select_by_primarykey_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProDictionarys, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProDictionarys',
                    payload: response,
                });

                if (callback) callback();
            },
            *delete_by_map_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProDictionarys, payload);
                yield put({
                    type: 'deleteByMapForProDictionarys',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProDictionarys, {});
                yield put({
		                type: 'queryPageForProDictionarys',
		                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProDictionarys, payload);
                yield put({
                    type: 'updateByMapForProDictionarys',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProDictionarys, {});
                yield put({
	                type: 'queryPageForProDictionarys',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProDictionarys, payload);
                yield put({
                    type: 'getOneForProDictionarys',
                    payload: response,
                });

                if (callback) callback();
            },
            *count_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(countForProDictionarys, payload);
                yield put({
                    type: 'countForProDictionarys',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProDictionarys, payload);
                yield put({
                    type: 'insertBatchForProDictionarys',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProDictionarys, {});
                yield put({
		                type: 'queryPageForProDictionarys',
		                payload: responsedata,
                });


                if (callback) callback();
            },
            *delete_batch_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProDictionarys, payload);
                yield put({
                    type: 'deleteBatchForProDictionarys',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProDictionarys, {});
                yield put({
		                type: 'queryPageForProDictionarys',
		                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProDictionarys, payload);
                yield put({
                    type: 'updateBatchForProDictionarys',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProDictionarys, {});
                yield put({
		                type: 'queryPageForProDictionarys',
		                payload: responsedata,
                });

                if (callback) callback();
            },
            
            *get_all_for_prodictionarys_type({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProDictionarysType, payload);
                yield put({
                    type: 'getAllForProDictionarysType',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *get_all_prodictionarys_type_by_select({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProDictionarysType, payload);
                yield put({
                    type: 'getAllProDictionarysTypeBySelect',
                    payload: response,
                });

                if (callback) callback(response);
            },
                        
            *get_all_children({ payload, callback }, { call, put }) {
                const response = yield call(getAllChildren, payload);
                yield put({
                    type: 'getAllChildren',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *insert_for_prodictionarys_type({ payload, callback }, { call, put }) {
                const response = yield call(insertForProDictionarysType, payload);
//              yield put({
//                  type: 'insertForProDictionarysType',
//                  payload: response,
//              });

                const responsedata = yield call(getAllForProDictionarysType, {});
                yield put({
		                type: 'getAllForProDictionarysType',
		                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *update_for_prodictionarys_type({ payload, callback }, { call, put }) {
                const response = yield call(updateForProDictionarysType, payload);
//              yield put({
//                  type: 'updateForProDictionarysType',
//                  payload: response,
//              });

                const responsedata = yield call(getAllForProDictionarysType, {});
                yield put({
		                type: 'getAllForProDictionarysType',
		                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *delete_by_primarykey_for_prodictionarys_type({ payload,callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProDictionarysType, payload);
//              yield put({
//                  type: 'deleteByPrimaryKeyForProDictionarysType',
//                  payload: response,
//              });

                const responsedata = yield call(getAllForProDictionarysType, {});
                yield put({
		                type: 'getAllForProDictionarysType',
		                payload: responsedata,
                });
								
								if (callback) callback(response);
            },
            *query_page_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProDictionarys, payload);
                yield put({
                    type: 'queryPageForProDictionarys',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(insertForProDictionarys, payload);
//              yield put({
//                  type: 'insertForProDictionarys',
//                  payload: response,
//              });

//              const responsedata = yield call(queryPageForProDictionarys, {dictid: payload.dictid});
//              yield put({
//		                type: 'queryPageForProDictionarys',
//		                payload: responsedata,
//              });
                if (callback) callback(response);
            },
            *update_for_prodictionarys({ payload, callback }, { call, put }) {
                const response = yield call(updateForProDictionarys, payload);
//              yield put({
//                  type: 'updateForProDictionarys',
//                  payload: response,
//              });

//              const responsedata = yield call(queryPageForProDictionarys, {});
//              yield put({
//		                type: 'queryPageForProDictionarys',
//		                payload: responsedata,
//              });

                if (callback) callback(response);
            },
            *delete_by_primarykey_for_prodictionarys({ payload,callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProDictionarys, payload);
//              yield put({
//                  type: 'deleteByPrimaryKeyForProDictionarys',
//                  payload: response,
//              });

//              const responsedata = yield call(queryPageForProDictionarys, {dictid: payload.dictid});
//              yield put({
//		                type: 'queryPageForProDictionarys',
//		                payload: responsedata,
//              });
								
				if (callback) callback(response);
            },

    },

    reducers: {

        selectByPrimaryKeyForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProDictionarys(state, action) {
            return {
                ...state,
                dictionarysTree: action.payload,
            };
        },
        getAllForProDictionarys(state, action) {
            return {
                ...state,
                dictionarysTree: action.payload,
            };
        },
        countForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
               
        updateBatchForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProDictionarys(state, action) {

        },
        updateForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByPrimaryKeyForProDictionarys(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProDictionarysType(state, action) {
            return {
                ...state,
                dictionarysTree: action.payload,
            };
        },
        insertForProDictionarysType(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProDictionarysType(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByPrimaryKeyForProDictionarysType(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllChildren(state, action) {
            return {
                ...state,
                cascaderList: action.payload,
            };
        },
        getAllProDictionarysTypeBySelect(state, action) {
            return {
                ...state,
                dictionarysTypeBySelect: action.payload,
            };
        },
    },
};
